home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / utilit~1 / initsnb.zoo / init / lib / wtmp.c < prev   
Encoding:
C/C++ Source or Header  |  1992-10-22  |  909 b   |  47 lines

  1. /*
  2.  * BSD style wtmp updating routine Version 1.0 (c) S.R.Usher 1991.
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <fcntl.h>
  7. #include <utmp.h>
  8. #include <errno.h>
  9.  
  10. #define WTMP_FILE    "/var/adm/wtmp"
  11.  
  12. void write_wtmp(line, name, host, time)
  13. char *line;
  14. char *name;
  15. char *host;
  16. unsigned long time;
  17. {
  18.     register int returned_val;
  19.     int fd;
  20.     int counter = 0;
  21.     struct utmp entry;
  22.  
  23.     if ((fd = open(WTMP_FILE, (O_RDWR | O_APPEND))) == -1)
  24.     {
  25.         printf("write_wtmp: %s\n", sys_errlist[errno]);
  26.         return -1;
  27.     }
  28.  
  29. /*
  30.  * Note, doing this in this order means that it doesn't matter about the Null
  31.  * bytes strncpy adds the the strings if they are greater than 8/16 bytes!
  32.  */
  33.  
  34.     strncpy(entry.ut_line, line, 8);
  35.     strncpy(entry.ut_name, name, 8);
  36.     strncpy(entry.ut_host, host, 16);
  37.     entry.ut_time = time;
  38.  
  39.     if (write(fd, &entry, sizeof(struct utmp)) == -1)
  40.     {
  41.         printf("write_wtmp: %s\n", sys_errlist[errno]);
  42.         return -1;
  43.     }
  44.  
  45.     close(fd);
  46. }
  47.